package com.realphim.app.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.realphim.app.R;
import com.realphim.app.model.ModelPhim;

public class AdapterPhimOnlyThumb extends BaseAdapter {

    public static final String TAG = "AdapterPhimCategory";

    private LayoutInflater inflater = null;

    private List<ModelPhim> listPhim;

    private int maxLenght = 0;

    public AdapterPhimOnlyThumb(Context context, List<ModelPhim> listPhim) {
        this.listPhim = listPhim;
        inflater = ((Activity) context).getLayoutInflater();
        maxLenght = context.getResources().getInteger(R.integer.max_char);
    }

    @Override
    public int getCount() {
        return listPhim.size();
    }

    @Override
    public ModelPhim getItem(int position) {
        return listPhim.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    private class Holder {
        ImageView ivThumbnail;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi = convertView;
        if (vi == null) {
            vi = inflater.inflate(R.layout.row_phim_category, null);
            Holder holder = new Holder();
            holder.ivThumbnail = (ImageView) vi.findViewById(R.id.ivThumbnail);
            vi.setTag(holder);
        }
        ModelPhim phim = listPhim.get(position);
        Holder holder = (Holder) vi.getTag();

        if (phim.thumbnailBitmap != null) {
            holder.ivThumbnail.setImageBitmap(phim.thumbnailBitmap);
        } else {
            holder.ivThumbnail.setImageBitmap(null);
        }

        return vi;

    }

}
